import {simplePost} from "../utils/request";
import {miError} from "../utils/exception";
import {showToastSuccess} from "../utils/tool";

const goodsCartService = {
    add(params){
        const app = getApp()

        return new Promise(resolve => {
            simplePost("/goodsCart/add",params).then(r => {
                if (typeof params.goods_id == 'undefined'){
                    throw miError("缺少商品id：goods_id")
                }
                if (typeof params.goods_sku_id == 'undefined'){
                    throw miError("缺少规格id：goods_sku_id")
                }
                if (typeof params.num == 'undefined'){
                    throw miError("缺少数量：num")
                }
                // 更新用户信息中的购物车商品数量
                app.globalData.cartNum = r.num
                showToastSuccess("操作成功")
                resolve(r)
            })
        })
    }
}

export default goodsCartService
